import cgi
import cgitb; cgitb.enable()

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

class MainPage(webapp.RequestHandler):
	def get(self):
		from lib import Logger;
		
		logs = Logger.getLogs();
		
		self.response.out.write( '<html><head><title>Logs</title></head><body><a href="clearLogs">clear logs</a><table cellpadding="5">');
		self.response.out.write('<tr><td>message</td></tr>');


		for log in logs:
			self.response.out.write('<tr>');
			self.response.out.write('<td>' + Logger.displayLog(log) + '</td>');
			self.response.out.write('</tr>');

		self.response.out.write('</table></body></html>');

		
class ClearPage(webapp.RequestHandler):
	def get(self):

		from lib import Logger;
		
		if(self.request.get('clear') !=None):
			Logger.clearLogs();
		
		self.redirect('/logs.html');

		


application = webapp.WSGIApplication(
					[('/logs.html', MainPage),
					 ('/clearLogs', ClearPage)
					
					],
					debug=True)

#def main():

run_wsgi_app(application)

#if __name__ == "__main__":
#	main()
